package view;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JFrame;

import model.FileParser;
import model.State;

/**
 * Class to logoout of the system.
 * @author Sarah George
 * @version Autumn 2012
 */
@SuppressWarnings("serial")
public class LogoutAction extends AbstractAction {
	
	/**
	 * Field to hold the current state of the system.
	 */
	private State my_state;
	
	/**
	 * Field that holds the GUIView JFrame.
	 */
	private JFrame my_frame;
	
	/**
	 * Constructor for the logout action.
	 * @param the_state the current state of the system.
	 * @param the_frame the gui view JFrame.
	 */
	public LogoutAction(State the_state, JFrame the_frame) {
		super("Logout");
	    putValue(Action.MNEMONIC_KEY, KeyEvent.VK_L);
	    putValue(Action.SELECTED_KEY, true);
	    my_state = the_state;
	    my_frame = the_frame;
	}

	/**
	 * Method to logout. Creates new login gui and disposes the current frame.
	 * @param e the action event that triggers this method.
	 */
	@Override
	public void actionPerformed(ActionEvent e) {
		FileParser fp = my_state.getParser();
		FileParser new_parser = new FileParser();
		new_parser.init("data.xml");
		my_state = new State(new_parser);
		new LoginFrame(my_state).start();
		my_frame.dispose();
	}
}//End class Logout action.